package com.ruoyi.web.controller.system;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.demo.domain.SysMeetroom;
import com.ruoyi.web.controller.service.ISysMeetroomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sys_meet_roomController
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@Controller
@RequestMapping("/system/meetroom")
public class SysMeetroomController extends BaseController
{
    private String prefix = "system/meetroom";

    @Autowired
    private ISysMeetroomService sysMeetroomService;

    @RequiresPermissions("system:meetroom:view")
    @GetMapping()
    public String meetroom()
    {
        return prefix + "/meetroom";
    }

    /**
     * 查询sys_meet_room列表
     */
    @RequiresPermissions("system:meetroom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysMeetroom sysMeetroom)
    {
        startPage();
        List<SysMeetroom> list = sysMeetroomService.selectSysMeetroomList(sysMeetroom);
        return getDataTable(list);
    }

    /**
     * 导出sys_meet_room列表
     */
    @RequiresPermissions("system:meetroom:export")
    @Log(title = "sys_meet_room", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysMeetroom sysMeetroom)
    {
        List<SysMeetroom> list = sysMeetroomService.selectSysMeetroomList(sysMeetroom);
        ExcelUtil<SysMeetroom> util = new ExcelUtil<SysMeetroom>(SysMeetroom.class);
        return util.exportExcel(list, "sys_meet_room数据");
    }

    /**
     * 新增sys_meet_room
     */
    @GetMapping("/add")
    public String add(Model model)
    {
        SysUser sysUser = getSysUser();
        model.addAttribute("user",sysUser);
        return prefix + "/add";
    }

    /**
     * 新增保存sys_meet_room
     */
    @RequiresPermissions("system:meetroom:add")
    @Log(title = "sys_meet_room", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysMeetroom sysMeetroom)
    {
        return toAjax(sysMeetroomService.insertSysMeetroom(sysMeetroom));
    }

    /**
     * 修改sys_meet_room
     */
    @RequiresPermissions("system:meetroom:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysMeetroom sysMeetroom = sysMeetroomService.selectSysMeetroomById(id);
        mmap.put("sysMeetroom", sysMeetroom);
        SysUser sysUser = getSysUser();
        mmap.put("user",sysUser);
        return prefix + "/edit";
    }


    @GetMapping("/xiang/{id}")
    public String xiang(@PathVariable("id") Long id, ModelMap mmap) throws ParseException {

        SysMeetroom sysMeetroom = sysMeetroomService.selectSysMeetroomById(id);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(sysMeetroom.getCreateTime());
        sysMeetroom.setCreTime(format);
        mmap.put("sysMeetroom", sysMeetroom);
        SysUser sysUser = getSysUser();
        mmap.put("user",sysUser);
        return prefix + "/xiang";
    }

    /**
     * 修改保存sys_meet_room
     */
    @RequiresPermissions("system:meetroom:edit")
    @Log(title = "sys_meet_room", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysMeetroom sysMeetroom)
    {
        return toAjax(sysMeetroomService.updateSysMeetroom(sysMeetroom));
    }

    /**
     * 删除sys_meet_room
     */
    @RequiresPermissions("system:meetroom:remove")
    @Log(title = "sys_meet_room", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysMeetroomService.deleteSysMeetroomByIds(ids));
    }
}
